package edu.rjxy.xjdx.emps.servlet;

import edu.rjxy.xjdx.emps.common.domain.Employee;
import edu.rjxy.xjdx.emps.common.utils.PageInfo;
import edu.rjxy.xjdx.emps.service.EmployeeService;
import edu.rjxy.xjdx.emps.service.EmployeeServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/listEmps")
public class ListEmpServlet extends HttpServlet {
    EmployeeService employeeService = new EmployeeServiceImpl();
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String pageNoTxt = request.getParameter("pageNo");
        String pageSizeTxt=request.getParameter("pageSize");
        int pageNo = pageNoTxt==null?1:Integer.parseInt(pageNoTxt.trim());
        int pageSize = pageSizeTxt==null?10:Integer.parseInt(pageSizeTxt.trim());

        PageInfo<Employee> page = employeeService.findEmpByPage(pageNo, pageSize);
        request.setAttribute("page",page);
        request.getRequestDispatcher("pages/emp-list.jsp").forward(request,response);
    }
}

/*    当前页码  pageNo
    每页显示数量 pageSize  10
        总数: count     112
        页数 ：page = (int)(count/pageSize) + (count%pageSize==0?0:1)
        limit  ? ,?    (pageNo-1)*pageSize,pageSize
*/
